import request from '/@/utils/request'
import requestFile from '/@/utils/requestFile'
const serverContextPath = '/filemng'
export function fileApi() {
	return {
		serverContextPath: serverContextPath,
		/**
		 * 分页查询
		 * @param {'page': this.pageIndex,
					'limit': this.pageSize,
					'dataForm': this.dataForm} params 
		*/
		queryPage: (params: any) => {
			return request({
				url: serverContextPath + '/file/list',
				method: 'post',
				data: params
			})
		},

		/**
		 * 上传文件
		 * @param {*} formData 
		 */
		uploadFile: (formData: any) => {
			return requestFile({
				url: serverContextPath + '/file/improtCommon',
				method: 'post',
				data: formData
			})
		},

		/**
		 * 下载文件
		 * @param {*} id 
		 */
		downloadFile: (id: any) => {
			var a = document.createElement("a");
			a.href = import.meta.env.VITE_API_URL + serverContextPath + "/file/downloadFile/" + id
			a.click();
		},

		/**
		 * 下载文件,批量压缩包
		 * @param {*} id 
		 */
		downloadFiles: (id: any) => {
			var a = document.createElement("a")
			a.href = import.meta.env.VITE_API_URL + serverContextPath + "/file/downloads/" + id
			a.click()
		},

		/**
		 * 删除文件
		 * @param {*} id 
		 */
		delete: (id: any) => {
			return  request({
				url: serverContextPath + "/file/delete",
				method: "post",
				data: id
			})
		},

		/**
		 * 根据业务id查询附件信息
		 * @param {*} businessId 
		 */
		getFileListByBusId: (businessId: any) => {
			return  request({
				url: serverContextPath + '/file/getFileListByBusId/' + businessId,
				method: 'get'
			})
		}
	}
}